package com.zhiche.lisa.lspm.service.trailer.impl;


import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.utils.Account.AccountUtil;
import com.zhiche.lisa.core.utils.Account.JwtAccountVO;
import com.zhiche.lisa.lspm.dao.mapper.trailer.TrailerAuditLogMapper;
import com.zhiche.lisa.lspm.dao.model.trailer.TrailerAuditLog;
import com.zhiche.lisa.lspm.service.trailer.ITrailerAuditLogService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 挂车认证日志 服务实现类
 * </p>
 *
 * @author qichao
 * @since 2018-06-10
 */
@Service
public class TrailerAuditLogServiceImpl extends ServiceImpl<TrailerAuditLogMapper, TrailerAuditLog> implements ITrailerAuditLogService {

    @Override
    public void batchInsertLog(List<Long> trailerIds,Integer auditResult) throws BaseException {
        try{
            JwtAccountVO jwtAccountVO = AccountUtil.getAccountInfoFromSecurityContext();
            List<TrailerAuditLog> lists = Lists.newArrayList();
            trailerIds.forEach(trailerId -> {
                TrailerAuditLog trailerAuditLog = new TrailerAuditLog();
                if(Objects.nonNull(jwtAccountVO)){
                    trailerAuditLog.setCreator(jwtAccountVO.getAccountId());
                    trailerAuditLog.setTenantId(Long.parseLong(jwtAccountVO.getTenantId()));
                }
                trailerAuditLog.setTrailerId(trailerId);
                trailerAuditLog.setAuditResult(auditResult);
                lists.add(trailerAuditLog);
            });
            this.insertBatch(lists);
        }
        catch (Exception ex){
            throw new BaseException(ex.getMessage());
        }
    }
}
